<?php
namespace App\Http\Forms;

use App\Library\OSS;
use Kris\LaravelFormBuilder\Form;

class DiscountForm extends Form
{
    public function buildForm()
    {
        $this
            ->add('shop_id', 'select', [
                'attr'  => ['class' => "form-control select2", 'id' => "shops-select"],
                'label' => "选择门店",
                'rules' => 'required|integer',
                'choices' => $this->getData('shops')??[],
            ])
            ->add('title', 'text', [
                'label' => "折扣名称",
                'rules' => 'required|string',
            ])
            ->add('limit', 'text', [
                'label' => "限制金额",
                'rules' => "required|integer",
            ])
            ->add('ratio', 'text', [
                'label' => "折扣",
                'rules' => "required|numeric|between:0.01,9.99",
            ])
            // ->add("goods_id", 'select', [
            //     'attr' => ['class' => "form-control select2", 'multiple' => "multiple", 'id' => "goods-select"],
            //     'label' => "适用范围",
            //     'rules' => 'nullable|array',
            //     'choices' => $this->getData('goods')??[],
            // ])
            ->add("link_id", 'select', [
                'attr' => ['class' => "form-control select2", 'multiple' => "multiple", 'id' => "package-select"],
                'label' => "适用范围(套系)",
                'rules' => 'nullable|array',
                'choices' => $this->getData('package')??[],
            ])
            ->add("link_id2", 'select', [
                'attr' => ['class' => "form-control select2", 'multiple' => "multiple", 'id' => "goods-select"],
                'label' => "适用范围(商品)",
                'rules' => 'nullable|array',
                'choices' => $this->getData('goods')??[],
            ])
            ->add('submit', 'submit', [
                'attr' => ['class' => "form-control btn btn-success"],
                'label' => '保存',
            ]);
    }
}
